﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;

namespace CardsServer.WCF
{
public partial interface IService
{
[OperationContract]
string CardOpen_D_Add(CardOpen_D model ,int ACID);


[OperationContract]
string CardOpen_D_Update(CardOpen_D model ,int ACID);


[OperationContract]
string CardOpen_DBydid_Delete(int did,int ACID);


[OperationContract]
CardOpen_D CardOpen_DBydid_Get(int did,int ACID );


[OperationContract]
List<CardOpen_D> CardOpen_D_Get(string sortBy,int ACID);




}
public partial class Service : IService
{
#region  添加CardOpen_D表数据
/// <summary>
/// 添加CardOpen_D
/// </summary>
/// <param name="model">CardOpen_D实体</param>
/// <returns>空或错误</returns>
public string CardOpen_D_Add(CardOpen_D model,int ACID)
{
if(model.did==null )
{
return "『详单流水号』不能为空！";
}
if(model.HJ==null )
{
return "『合计』不能为空！";
}
if(model.activeDate==null )
{
return "『卡片激活日期』不能为空！";
}
if(model.yue==null )
{
return "『卡内预存金额』不能为空！";
}
if(model.amount==null )
{
return "『价格』不能为空！";
}
if(model.quantity==null )
{
return "『数量』不能为空！";
}
if(string.IsNullOrEmpty(model.unit))
{
return "『单位』不能为空！";
}
if(model.price==null )
{
return "『单价』不能为空！";
}
if(model.CardPrice==null )
{
return "『空卡价格』不能为空！";
}
if(model.monthflag==null )
{
return "『按月核算标志』不能为空！";
}
if(model.ComboID==null )
{
return "『套餐ID』不能为空！";
}
if(string.IsNullOrEmpty(model.phone))
{
return "『号码』不能为空！";
}
if(string.IsNullOrEmpty(model.cno))
{
return "『串号』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『主单单据号』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_D.Count(p=>p.did==model.did)>0)
{
return "主键已存在！";
}
ctx.CardOpen_D.InsertOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 添加失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  添加CardOpen_D表数据事物用重构
/// <summary>
/// 添加CardOpen_D事物用重构
/// </summary>
/// <param name="model">CardOpen_D实体</param>
/// <returns>空或错误</returns>
private string CardOpen_D_Add(CardOpen_D model,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(model.did==null )
{
return "『详单流水号』不能为空！";
}
if(model.HJ==null )
{
return "『合计』不能为空！";
}
if(model.activeDate==null )
{
return "『卡片激活日期』不能为空！";
}
if(model.yue==null )
{
return "『卡内预存金额』不能为空！";
}
if(model.amount==null )
{
return "『价格』不能为空！";
}
if(model.quantity==null )
{
return "『数量』不能为空！";
}
if(string.IsNullOrEmpty(model.unit))
{
return "『单位』不能为空！";
}
if(model.price==null )
{
return "『单价』不能为空！";
}
if(model.CardPrice==null )
{
return "『空卡价格』不能为空！";
}
if(model.monthflag==null )
{
return "『按月核算标志』不能为空！";
}
if(model.ComboID==null )
{
return "『套餐ID』不能为空！";
}
if(string.IsNullOrEmpty(model.phone))
{
return "『号码』不能为空！";
}
if(string.IsNullOrEmpty(model.cno))
{
return "『串号』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『主单单据号』不能为空！";
}
if(ctx.CardOpen_D.Count(p=>p.did==model.did)>0)
{
return "主键已存在！";
}
ctx.CardOpen_D.InsertOnSubmit(model);
return string.Empty;
}
#endregion

#region  修改CardOpen_D表数据
/// <summary>
/// 修改CardOpen_D
/// </summary>
/// <param name="model">CardOpen_D实体</param>
/// <returns>空或错误</returns>
public string CardOpen_D_Update(CardOpen_D model,int ACID)
{
if(model.did==null )
{
return "『详单流水号』不能为空！";
}
if(model.HJ==null )
{
return "『合计』不能为空！";
}
if(model.activeDate==null )
{
return "『卡片激活日期』不能为空！";
}
if(model.yue==null )
{
return "『卡内预存金额』不能为空！";
}
if(model.amount==null )
{
return "『价格』不能为空！";
}
if(model.quantity==null )
{
return "『数量』不能为空！";
}
if(string.IsNullOrEmpty(model.unit))
{
return "『单位』不能为空！";
}
if(model.price==null )
{
return "『单价』不能为空！";
}
if(model.CardPrice==null )
{
return "『空卡价格』不能为空！";
}
if(model.monthflag==null )
{
return "『按月核算标志』不能为空！";
}
if(model.ComboID==null )
{
return "『套餐ID』不能为空！";
}
if(string.IsNullOrEmpty(model.phone))
{
return "『号码』不能为空！";
}
if(string.IsNullOrEmpty(model.cno))
{
return "『串号』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『主单单据号』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_D.Count(p=>p.did==model.did)!= 1)
{
return "未找到指定记录或记录不唯一！";
}
CardOpen_D CardOpen_Dmodel=ctx.CardOpen_D.Single(p => p.did==model.did);
if(model.did!=null )
{
CardOpen_Dmodel.did=model.did;
}
if(!string.IsNullOrEmpty(model.pid))
{
CardOpen_Dmodel.pid=model.pid;
}
if(!string.IsNullOrEmpty(model.cno))
{
CardOpen_Dmodel.cno=model.cno;
}
if(!string.IsNullOrEmpty(model.phone))
{
CardOpen_Dmodel.phone=model.phone;
}
if(model.ComboID!=null )
{
CardOpen_Dmodel.ComboID=model.ComboID;
}
if(model.monthflag!=null )
{
CardOpen_Dmodel.monthflag=model.monthflag;
}
if(model.CardPrice!=null )
{
CardOpen_Dmodel.CardPrice=model.CardPrice;
}
if(model.price!=null )
{
CardOpen_Dmodel.price=model.price;
}
if(!string.IsNullOrEmpty(model.unit))
{
CardOpen_Dmodel.unit=model.unit;
}
if(model.quantity!=null )
{
CardOpen_Dmodel.quantity=model.quantity;
}
if(model.amount!=null )
{
CardOpen_Dmodel.amount=model.amount;
}
if(model.yue!=null )
{
CardOpen_Dmodel.yue=model.yue;
}
if(model.activeDate!=null )
{
CardOpen_Dmodel.activeDate=model.activeDate;
}
if(model.HJ!=null )
{
CardOpen_Dmodel.HJ=model.HJ;
}
if(!string.IsNullOrEmpty(model.WH_pid))
{
CardOpen_Dmodel.WH_pid=model.WH_pid;
}
if(!string.IsNullOrEmpty(model.remarks))
{
CardOpen_Dmodel.remarks=model.remarks;
}
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 修改失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除CardOpen_D表Bydid数据
/// <summary>
/// 删除CardOpen_DBydid
/// </summary>
/// <param name="did">详单流水号</param>
/// <returns>空或错误</returns>
public string CardOpen_DBydid_Delete(int did,int ACID)
{
if(did==null )
{
return "『详单流水号』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_D.Count(p=>p.did==did)!=1)
{
return null;
}
CardOpen_D model=ctx.CardOpen_D.Single(p => p.did== did);
ctx.CardOpen_D.DeleteOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 删除失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除CardOpen_D表Bydid数据[事物用重构]
/// <summary>
/// 删除CardOpen_DBydid[事物用重构]
/// </summary>
/// <param name="did">详单流水号</param>
/// <returns>空或错误</returns>
private string CardOpen_DBydid_Delete(int did,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(did==null )
{
return "『详单流水号』不能为空！";
}
if(ctx.CardOpen_D.Count(p=>p.did==did)!=1)
{
return null;
}
CardOpen_D model=ctx.CardOpen_D.Single(p => p.did== did);
ctx.CardOpen_D.DeleteOnSubmit(model);
return string.Empty;
}
#endregion

#region  获取CardOpen_D表Bydid数据
/// <summary>
/// 获取CardOpen_DBydid
/// </summary>
/// <param name="did">详单流水号</param>
/// <returns>当前表</returns>
public CardOpen_D CardOpen_DBydid_Get(int did,int ACID)
{
if(did==null )
{
return null;
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_D.Count(p=>p.did==did)!=1)
{
return null;
}
return ctx.CardOpen_D.SingleOrDefault(p=>p.did==did);
}
catch (Exception ex)
{
return null;
}
}
}
#endregion

#region  获取CardOpen_D表数据
/// <summary>
/// 获取CardOpen_D
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<CardOpen_D></returns>
public List<CardOpen_D> CardOpen_D_Get(Expression<Func<CardOpen_D, bool>> predicate , string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_D.ToList();
}
 else 
{
return ctx.CardOpen_D.OrderBy(sortBy).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_D.Where(predicate).ToList();
}
 else 
{
return ctx.CardOpen_D.Where(predicate).OrderBy(sortBy).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion

#region  获取CardOpen_D表数据
/// <summary>
/// 获取CardOpen_D
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<CardOpen_D></returns>
public List<CardOpen_D> CardOpen_D_Get(string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
return CardOpen_D_Get(null,sortBy, ACID);
}
catch (Exception)
{
return null;
}
}
}
#endregion

#region  获取CardOpen_D表数据计数
/// <summary>
/// 获取CardOpen_D表数据计数
/// </summary>
/// <returns>List<CardOpen_D></returns>
public int CardOpen_D_GetCount(Expression<Func<CardOpen_D, bool>> predicate,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
return ctx.CardOpen_D.Count();

}
 else
{
return ctx.CardOpen_D.Where(predicate).Count();
}
}
catch 
{
return 0;
}
}
}
#endregion

#region  获取CardOpen_D分页表数据
/// <summary>
/// 获取CardOpen_D分页表数据
/// </summary>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<CardOpen_D></returns>
public List<CardOpen_D> CardOpen_D_Getpage(int pageIndex, int pageSize,Expression<Func<CardOpen_D, bool>> predicate ,string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_D.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.CardOpen_D.OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_D.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.CardOpen_D.Where(predicate).OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion

#region  批量修改CardOpen_D表数据
/// <summary>
/// 批量修改CardOpen_D
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_D, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<CardOpen_D,CardOpen_D>> 更新表达式树</param>
/// <param name="returns">影响记录数</param>
public int CardOpen_D_batchUpdate(Expression<Func<CardOpen_D, bool>> predicate,Expression<Func<CardOpen_D, CardOpen_D>> updater,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.CardOpen_D.Update(predicate, updater);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion

#region  批量修改CardOpen_D表数据事物用重构
/// <summary>
/// 批量修改CardOpen_D事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_D, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<CardOpen_D,CardOpen_D>> 更新表达式树</param>
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int CardOpen_D_batchUpdate(Expression<Func<CardOpen_D, bool>> predicate,Expression<Func<CardOpen_D, CardOpen_D>> updater,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.CardOpen_D.Update(predicate, updater);
return ok;
}
#endregion

#region  批量删除CardOpen_D表数据
/// <summary>
/// 批量删除CardOpen_D
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_D, bool>></param> 查找表达式树
/// <param name="returns">影响记录数</param>
public int CardOpen_D_batchDel(Expression<Func<CardOpen_D, bool>> predicate,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.CardOpen_D.Delete(predicate);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion

#region  批量删除CardOpen_D表数据事物用重构
/// <summary>
/// 批量删除CardOpen_D事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_D, bool>></param> 查找表达式树
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int CardOpen_D_batchDel(Expression<Func<CardOpen_D, bool>> predicate,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.CardOpen_D.Delete(predicate);
return ok;
}
#endregion


}
}

